package com.ruoyi.eqmonitor.dispose.resolve;

import cn.hutool.json.JSONArray;
import com.ruoyi.eqmonitor.dtos.OptDeviceDto;
import com.ruoyi.eqmonitor.service.IOptDeviceMonitorConfigService;
import com.ruoyi.eqmonitor.utils.Constant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * 阈值判断处理
 */
@Slf4j
@Component
public class MonitorConfigResolve implements MqttMessageResolve {

    @Resource
    private IOptDeviceMonitorConfigService monitorConfigService;

    @Override
    public boolean support(int msgType) {
        // 参数 或 监测 数据
        return Constant.MqttMsgType.PARAMETER.getCode() == msgType ||
                Constant.MqttMsgType.MONITOR_DATA.getCode() == msgType;
    }

    // 改为自行判断报警
    @Override
    public boolean resolve(String snCode, OptDeviceDto optDevice, JSONArray messageArray) {
        monitorConfigService.validateConfigAndDoAlarm(optDevice, messageArray);
        return true;
    }
}
